const GoodsComments = require("../../model/goodsComments")

module.exports = async(req, res) => {
    const { uid, sid } = req.body;
    let resData = {
        data: req.body,
        meta: {
            code: 200,
            msg: "已添加留言!",
        },
    };
    let resArray = [];
    let goodsComments = await GoodsComments.findOne({ sid });
    // if (goodsComments == null) {
    if (true) {
        try {
            // post请求中的用户信息就是客户端需要新增的用户
            await GoodsComments.create(req.body);
        } catch (err) {
            for (item in err.errors) {
                resArray.push(err.errors[item].message);
            }
            // res.status(400);
            resData.meta.code = 400;
            resData.meta.msg = resArray.join(",");
        }
        res.send(resData);
    } else {
        resData.meta.code = 400;
        resData.meta.msg = "添加留言失败!";
        resData.data = {};
        res.send(resData);
    }
}